from django.shortcuts import render,HttpResponse
# Create your views here.
from .models import  Device,monitor



def devall(request):

    dev_all = Device.objects.count()
    return render(request, 'dev.html', {'all':dev_all})



def conf(request):

    if request.method == 'GET':
        device = Device.objects.all()

        return render(request, 'conf.html',{'devices':device})

    device = Device.objects.all()
    # huawei_command = request.POST.get
    # cisco_command = request.POST.get



    print(request.POST.get('cisco_command',))

    return render(request, 'conf.html', {'devices': device})



# ###  测试celery，自己手动指定定时任务
# from mycelery.sms.task import send_sms,send_sms2
# from mycelery.dingtalk.task import send_dingtalk_msg
# from datetime import datetime,timedelta
# def test(request):
#
#     # 1. 声明一个和celery一模一样的任务函数，但是我们可以导包来解决
#     # send_sms.delay("110")
#     # send_sms2.delay("119")
#
#     # send_sms.delay()
#     # 如果调用的任务函数没有参数，则不需要填写任何内容
#     msg= "1.1.1.1"
#     result = send_dingtalk_msg.delay(msg)
#     print(result.id)
#     ################################# 定时任务
#     # ctime = datetime.now()
#     # # 默认用utc时间
#     # utc_ctime = datetime.utcfromtimestamp(ctime.timestamp())
#     # time_delay = timedelta(seconds=10)
#     # task_time = utc_ctime + time_delay
#     # result = send_sms.apply_async(["911", ], eta=task_time)
#     # print(result.id)
#
#     return HttpResponse(result.id)




def webssh(request):

    connect={
        "host_ip":'10.55.1.204',
        "host_name":"huawei",
        "host_port":22,
        "sys_user_name":"admin",
        "sys_user_passwd":"admin@1234",

    }
    return  render(request,'ssh2.html',{"connect":connect})
























